<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品分类管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#category").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					if(isok==1){
						document.getElementById("tt").innerHTML="类别选择不正确，请重新选择";
					}else if(isok==2){
						document.getElementById("agent").innerHTML="该类别名称已存在！";
					}else{
						loading('正在提交，请稍等...');
						form.submit();
					}

				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
	<script>
		var iso=0;
		$(document).ready(function() {
			$("#name").blur(function () {
				var cate=$("#name").val();
				var reverflag=$("#categoryId").val();
				if(reverflag==1){
					document.getElementById("tt").innerHTML="类别选择不正确，请重新选择";
					isok=1;
				}else{
					document.getElementById("tt").innerHTML="*";
					$.ajax({
						type : "POST",
						url : "${ctx}/sys/category/checkCategory",
						data : "category="+cate,
						success : function(date) {
							if(date=='0'){
								document.getElementById("agent").innerHTML="*";
								isok=3;
							}else {
								document.getElementById("agent").innerHTML="该类别名称已存在！";
								isok=2;
							}
						}

					});

				}
			});

		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/category/list">分类列表</a></li>
		<li class="active"><a href="${ctx}/sys/category/form?id=${category.id}&parent.id=${category.parent.id}">类别${not empty category.id?'修改':'添加'}</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="category" action="${ctx}/sys/category/save" method="post" class="form-horizontal">
		<%--<form:hidden path="id"/>--%>
		<input type="hidden" name="id" value="${category.id}">
		<input type="hidden" name="parentIds" value="${category.parentIds}">
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">上级类别</label>
			<div class="controls">
                <sys:treeselect id="category" name="parent.id" value="${category.parent.id}" labelName="parent.name" labelValue="${category.parent.name}"
					title="菜单" url="/sys/category/treeData" extId="${category.id}" cssClass="required"/>
				<span class="help-inline"><font color="red" id="tt">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">名称:</label>
			<div class="controls">
				<input name="name" id="name" type="text" htmlEscape="false" maxlength="50" class="required input-xlarge" value="${category.name}"/>
				<span class="help-inline"><font color="red" id="agent">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图标:</label>
			<div class="controls">
				<sys:iconselect id="icon" name="icon" value="${category.icon}"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">排序:</label>
			<div class="controls">
			<input type="text"name="sort"htmlEscape="false" maxlength="50" class="required digits input-small"value="${category.sort}"/>
				<span class="help-inline">排列顺序，升序。</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<input  type="text"name="remarks" htmlEscape="false" rows="3" maxlength="200" value="${category.remarks}"class="input-xxlarge"/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>